﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using FirstFloor.Documents.IO;

namespace FirstFloor.Documents.Pdf
{
    /// <summary>
    /// Provides request helper methods.
    /// </summary>
    internal static class RequestHelper
    {
        /// <summary>
        /// Parses the identifier from a font request uri.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <param name="identifier">The identifier.</param>
        /// <returns></returns>
        public static bool TryParseFontIdentifier(string uri, out ObjectIdentifier identifier)
        {
            identifier = new ObjectIdentifier();

            if (uri.StartsWith("Resources/Fonts/")) {
                identifier = ParserUtility.ParseIdentifier(uri, 16);
                return true;
            }
            return false;
        }

        /// <summary>
        /// Parses the identifier from a image request uri.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <param name="identifier">The identifier.</param>
        /// <returns></returns>
        public static bool TryParseImageIdentifier(string uri, out ObjectIdentifier identifier)
        {
            identifier = new ObjectIdentifier();

            if (uri.StartsWith("Resources/Images/")) {
                identifier = ParserUtility.ParseIdentifier(uri, 17);
                return true;
            }
            return false;
        }

        /// <summary>
        /// Creates a request uri for the font having specified identifier.
        /// </summary>
        /// <param name="identifier">The identifier.</param>
        /// <returns></returns>
        public static string CreateFontRequestUri(ObjectIdentifier identifier)
        {
            return string.Format("/Resources/Fonts/{0}.{1}.ttf", identifier.Number, identifier.Generation);
        }

        /// <summary>
        /// Creates a request uri for the image having specified identifier.
        /// </summary>
        /// <param name="identifier">The identifier.</param>
        /// <param name="fileExtension">The file extension.</param>
        /// <returns></returns>
        public static string CreateImageRequestUri(ObjectIdentifier identifier, string fileExtension)
        {
            // note: file extension limited to what is listed in [Content_Types].xml
            return string.Format("/Resources/Images/{0}.{1}{2}", identifier.Number, identifier.Generation, fileExtension);
        }
    }
}
